package cn.com.yusys.yusp.custManager.web.rest;

import cn.com.yusys.yusp.custManager.domain.OcrmFCiFqScol;
import cn.com.yusys.yusp.custManager.domain.OcrmFCiFqSsolution;
import cn.com.yusys.yusp.custManager.service.FlexibleQuerySolutionService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @Author: zoie
 * @Description: 灵活查询方案
 * @Date: 2021/5/1
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/flexibleQuerySolution")
@Api(tags = "flexibleQuery")
public class FlexibleQuerySolutionResource extends CommonResource<OcrmFCiFqSsolution, Serializable> {

    @Autowired
    private FlexibleQuerySolutionService flexibleQuerySolutionService;

    @Override
    protected CommonService getCommonService() {
        return this.flexibleQuerySolutionService;
    }

    /**
     * 查询方案列表
     *
     * @param queryModel
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询方案列表", notes = "查询方案列表")
    public ResultDto<List<Map<String, Object>>> getList(QueryModel queryModel) {
        List<Map<String, Object>> list = flexibleQuerySolutionService.getList(queryModel);
        return new ResultDto<>(list);
    }

    /**
     * 保存方案及条件列
     *
     * @param parmas
     * @return
     * @throws ParseException
     */
    @PostMapping("/saveSolution")
    @ApiOperation(value = "保存方案及条件列", notes = "保存方案及条件列")
    public ResultDto<Integer> saveSolution(@RequestBody Map<?, ?> parmas) throws ParseException {
        System.out.println(parmas.get("solutionData").getClass().getDeclaredFields());
        System.out.println(parmas);

        List<OcrmFCiFqScol> scolList = JSONArray.parseArray((String) parmas.get("scolData"), OcrmFCiFqScol.class);
        List<OcrmFCiFqSsolution> solutionList = JSONArray.parseArray((String) parmas.get("solutionData"), OcrmFCiFqSsolution.class);
        return new ResultDto<>(flexibleQuerySolutionService.saveSolution(scolList, solutionList));
    }

    /**
     * 批量删除方案
     *
     * @param ids
     * @return
     */
    @PostMapping("/batchDeleteSolution/{ids}")
    @ApiOperation(value = "批量删除方案", notes = "批量删除方案")
    public ResultDto<Integer> batchDeleteSolution(@PathVariable String ids) {
        int result = flexibleQuerySolutionService.batchDeleteSolution(ids);
        return new ResultDto<>(result);

    }

}
